import request from '@/utils/request'

const api_name = '/role'

export default {
  // 查询所有用户
  listRole(pageNum, pageSize, searchObj) {
    return request({
      url: `${api_name}/list/${pageNum}/${pageSize}`,
      method: 'get',
      params: searchObj
    })
  },
  // 新增角色
  addRole(role) {
    return request({
      url: `${api_name}/add`,
      method: 'post',
      data: role
    })
  },
  // 检查名称是否已存在
  checkIsNameExist(searchObj) {
    return request({
      url: `${api_name}/checkIsNameExist`,
      method: 'post',
      params: searchObj
    })
  },
  // 修改角色
  updateRole(role) {
    return request({
      url: `${api_name}/update`,
      method: 'put',
      data: role
    })
  },
  // 删除角色
  deleteById(id) {
    return request({
      url: `${api_name}/delete/${id}`,
      method: 'delete'
    })
  },
  // 批量删除
  deleteBatch(ids) {
    return request({
      url: `${api_name}/deleteBatch`,
      method: 'delete',
      data: ids
    })
  },
  // 批量启用/禁用
  batchSetStatus(ids, status) {
    return request({
      url: `${api_name}/batchSetStatus/${status}`,
      method: 'post',
      data: ids
    })
  },
  //分配功能
  addRoleAndFunction(functionIds,roleId){
    return request({
      url: `${api_name}/addRoleAndFunction/${roleId}`,
      method: 'post',
      data: functionIds
    })
  }
}
